﻿
#region Usings

using FasterWPF;
using FasterWPFDemo.UserControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;

#endregion

namespace FasterWPFDemo
{
    //DockPanel
    public partial class TabItem06 : UserControl, IUserControlGuid
    {
        #region Events

        void myButton_Click(object sender, RoutedEventArgs e)
        {
            DockPanel container = sender.Cast<FrameworkElement>().GetParentFromChildElement<DockPanel>();

            //Add a FIND method to CommonExt ?

            MessageBox.Show("Change text on Hello World 1 and change 34 to gold background.");
            Border b = ((Border)container.Children[1]);
            string guidKey = CommonExt.GetKey(b);

            container.UpdateTextFoundByText(guidKey, "Hello World 1a", "Change Text 1");
           // container.UpdateLabelFoundByContent(guidKey, "3", "34");

            Label myLabel = container.FindLabelByContent(guidKey, "34");
            myLabel.Background = Brushes.Goldenrod;

            //List<TextBlock> listTextBlocks = container.FindTextBlocksByText(guidKey, "Change Text 1");
            //listTextBlocks[0].Background = Brushes.Goldenrod;
            
            //List<string> lo = container.GetChildKeysFromComposite<DockPanel>(guidKey);
            //foreach (string l in lo)
            //{
            //    MessageBox.Show(l.ToString());
            //}

            //List<object> lo = container.GetChildrenFromComposite<DockPanel>(guidKey);
            //foreach (object l in lo)
            //{
            //    MessageBox.Show(l.ToString());
            //}
        }

        void sortButton_Click(object sender, RoutedEventArgs e)
        {
            DockPanel container = sender.Cast<FrameworkElement>().GetParentFromChildElement<DockPanel>();
            container.SortByText<DockPanel>(0, 0, CommonExt.SortOrder.Desc, CommonExt.SortControlType.Label);
        }

        void my_MouseSingleClick(EventPattern<MouseButtonEventArgs> ve)
        {
            // e.GetLines(sender).ForEach(line => { System.Windows.MessageBox.Show(line); });  //1. works regardless what type of element was clicked, returning lines for all the elements in that row that are text

            // System.Windows.MessageBox.Show(e.GetTextRun());  //2. works only if a text run was clicked else returns empty string
            Border b = (Border)ve.Sender;
            System.Windows.MessageBox.Show("Remove: " + ve.EventArgs.GetKey(ve.Sender));
            DockPanel dpan = b.GetParentFromComposite<DockPanel>();
            dpan.RemoveByKey(ve.EventArgs.GetKey(ve.Sender));
        }

        #endregion
    }
}
